/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaPrincipal.java
 *
 * Created on Apr 7, 2011, 1:45:47 PM
 */

package spoc.interfaces;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import spoc.classes.BancoDeDados;

/**
 *
 * @author arthur
 */
public class JanelaPrincipal extends javax.swing.JFrame {

    private PainelConsultaClientes painelClientes;
    private PainelConsultaCortinas painelCortinas;
    private PainelConsultaMaterias painelMaterias;
    private PainelConsultaPedidos painelPedidos;

    /** Creates new form JanelaPrincipal */
    public JanelaPrincipal() {
        initComponents();
        this.setTitle(" SPOC - Sistema de Pedidos e Orçamento de Cortina ");
        //ImageIcon logo = new ImageIcon("./imagens/logo-16.gif");

        //this.setIconImage(logo.getImage());

        
        painelClientes = new PainelConsultaClientes();
        painelCortinas = new PainelConsultaCortinas();
        painelMaterias = new PainelConsultaMaterias();
        painelPedidos = new PainelConsultaPedidos();
        
        painelSplit.setRightComponent(painelClientes);

        ImageIcon icone = new ImageIcon("logo-42.png");
        setIconImage(icone.getImage());

        configurarFonte(botaoClientes, Color.BLACK, Font.BOLD, 16);
        configurarFonte(botaoCortina, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoMaterias, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoPedidos, Color.BLACK, Font.PLAIN, 12);
        
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.setSize(700,450);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelSplit = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        botaoClientes = new javax.swing.JButton();
        botaoCortina = new javax.swing.JButton();
        botaoMaterias = new javax.swing.JButton();
        botaoPedidos = new javax.swing.JButton();
        MenuPricipal = new javax.swing.JMenuBar();
        MenuSistema = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(850, 450));

        painelSplit.setDividerLocation(170);
        painelSplit.setDividerSize(0);
        painelSplit.setMinimumSize(new java.awt.Dimension(170, 400));
        painelSplit.setPreferredSize(new java.awt.Dimension(700, 350));

        jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel1.setMinimumSize(new java.awt.Dimension(170, 400));
        jPanel1.setPreferredSize(new java.awt.Dimension(170, 400));

        botaoClientes.setText("Clientes");
        botaoClientes.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoClientes(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoClientes);

        botaoCortina.setText("Cortinas");
        botaoCortina.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoCortina.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoProdutos(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoCortina);

        botaoMaterias.setText("Materias");
        botaoMaterias.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoMaterias.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoServicos(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoMaterias);

        botaoPedidos.setText("Pedidos");
        botaoPedidos.setPreferredSize(new java.awt.Dimension(150, 40));
        botaoPedidos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clicarBotaoVendas(evt);
                mudarFonte(evt);
            }
        });
        jPanel1.add(botaoPedidos);

        painelSplit.setLeftComponent(jPanel1);

        getContentPane().add(painelSplit, java.awt.BorderLayout.CENTER);

        MenuSistema.setText("Sistema");

        jMenuItem1.setText("Sair");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        MenuSistema.add(jMenuItem1);

        MenuPricipal.add(MenuSistema);

        setJMenuBar(MenuPricipal);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void clicarBotaoProdutos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoProdutos
        if(!painelSplit.getRightComponent().equals(painelCortinas)){
            painelSplit.setRightComponent(painelCortinas);
        }
}//GEN-LAST:event_clicarBotaoProdutos

    private void clicarBotaoServicos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoServicos
        if(!painelSplit.getRightComponent().equals(painelMaterias)){
            painelSplit.setRightComponent(painelMaterias);
        }
    }//GEN-LAST:event_clicarBotaoServicos

    private void clicarBotaoVendas(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoVendas
        if(!painelSplit.getRightComponent().equals(painelPedidos)){
            painelSplit.setRightComponent(painelPedidos);
        }
    }//GEN-LAST:event_clicarBotaoVendas

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        int resp = JOptionPane.showConfirmDialog(this, "Tem certeza que deseja sair do programa?", "Sair", JOptionPane.YES_NO_OPTION);

        if(resp == JOptionPane.YES_OPTION){
           BancoDeDados.Disconnect();
           System.exit(0);
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void mudarFonte(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mudarFonte
        configurarFonte(botaoClientes, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoCortina, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoMaterias, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(botaoPedidos, Color.BLACK, Font.PLAIN, 12);
        configurarFonte(evt.getComponent(), Color.BLACK, Font.BOLD, 16);
    }//GEN-LAST:event_mudarFonte

    private void clicarBotaoClientes(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicarBotaoClientes
        if(!painelSplit.getRightComponent().equals(painelClientes)){
            painelSplit.setRightComponent(painelClientes);
        }
    }//GEN-LAST:event_clicarBotaoClientes

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JanelaPrincipal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar MenuPricipal;
    private javax.swing.JMenu MenuSistema;
    private javax.swing.JButton botaoClientes;
    private javax.swing.JButton botaoCortina;
    private javax.swing.JButton botaoMaterias;
    private javax.swing.JButton botaoPedidos;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSplitPane painelSplit;
    // End of variables declaration//GEN-END:variables


    private void configurarFonte(java.awt.Component c, Color cor, int estilo, int tamanhoFonte){
        c.setForeground(cor);
        c.setFont(new Font("Tahoma", estilo, tamanhoFonte));
    }

    private void setIconImage(ImageIcon imageIcon) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
